package leecode

func longestConsecutive(nums []int) int {
	hashMap := make(map[int]bool)
	for i := 0; i < len(nums); i++ {
		hashMap[nums[i]] = true
	}
	var result int
	for key, _ := range hashMap {
		temp := key
		if !hashMap[temp-1] {
			for hashMap[temp+1] {
				temp++
			}
		}
		result = max(result, temp-key+1)
	}
	return result
}
